home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + sortseq.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
- #ifndef SORTSEQH
- #define SORTSEQH
-
-
- //------------------------------------------------------------------------------
- // sortseq: sorted sequences
- //
- // data structure: (2,4)-Trees
- //
- // Stefan Naeher (1989)
- //------------------------------------------------------------------------------
-
- #include <LEDA/ab_tree.h>
-
- typedef ab_tree_node* seq_item;
-
- #define sortseq(keytype,infotype) name3(keytype,infotype,sortseq)
-
- #define sortseqdeclare2(keytype,infotype)\
- \
- struct sortseq(keytype,infotype) : public ab_tree {\
- \
- int cmp(ent& x, ent& y) const { return compare(*(keytype*)&x,*(keytype*)&y); }\
- void clear_key(ent& x) const { Clear(*(keytype*)&x); }\
- void clear_inf(ent& x) const { Clear(*(infotype*)&x); }\
- void copy_key(ent& x) const { Copy(*(keytype*)&x); }\
- void copy_inf(ent& x) const { Copy(*(infotype*)&x); }\
- void print_key(ent& x) const { Print(*(keytype*)&x); }\
- void print_inf(ent& x) const { Print(*(infotype*)&x); }\
- \
- seq_item lookup(keytype y) const { return ab_tree::lookup(Ent(y)); }\
- seq_item locate(keytype y) const { return ab_tree::locate(Ent(y)); }\
- seq_item locate_pred(keytype y) const { return ab_tree::locate_pred(Ent(y)); }\
- \
- seq_item succ(seq_item x) const { return ab_tree::succ(x); }\
- seq_item succ(keytype y) const { return locate(y); }\
- \
- seq_item pred(seq_item x) const { return ab_tree::pred(x); }\
- seq_item pred(keytype y) const { return locate_pred(y); }\
- \
- seq_item insert(keytype y,infotype x)\
- { return ab_tree::insert(Ent(y),Ent(x)); } \
- \
- seq_item insert_at(seq_item it,keytype y,infotype x)\
- { return ab_tree::insert_at_node(it,Ent(y),Ent(x)); } \
- \
- void flip_items(seq_item a, seq_item b) { ab_tree::flip(a,b); }\
- void reverse_items(seq_item a, seq_item b) { ab_tree::reverse(a,b); }\
- \
- void del(keytype y) { ab_tree::del(Ent(y)); } \
- void del_item(seq_item it) { ab_tree::del_node(it); } \
- void change_inf(seq_item it, infotype i) { ab_tree::change_inf(it,Ent(i));}\
- keytype key(seq_item it) const { return keytype(ab_tree::key(it)); }\
- infotype inf(seq_item it) const { return infotype(ab_tree::inf(it)); } \
- \
- void split(seq_item x,sortseq(keytype,infotype)& S1,sortseq(keytype,infotype)& S2)\
- { ab_tree::split_at_item(x,(ab_tree&)S1,(ab_tree&)S2); }\
- \
- sortseq(keytype,infotype)& conc(sortseq(keytype,infotype)& S)\
- { ab_tree::conc((ab_tree&)S); return *this; }\
- \
- sortseq(keytype,infotype)() {}\
- sortseq(keytype,infotype)(const sortseq(keytype,infotype)& w) : ab_tree((ab_tree&)w) {}\
- \
- sortseq(keytype,infotype)& operator=(const sortseq(keytype,infotype)& w)\
- { ab_tree::operator=((ab_tree&)w); return *this; }\
- \
- ~sortseq(keytype,infotype)() { clear(); }\
- } ;
-
-
- // ----------------------------------------------------------------
- // iteration
- // ----------------------------------------------------------------
-
- #define forall_seq_items(i,S) for(i=(S).first_item(); i; i=(S).next_item(i))
-
-
- #endif
-